package cate.game.play.skill.passive.hero;

import cate.common.util.XT;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.proce.action.ctx.ActionCtx;
import cate.game.play.skill.FighterCD;
import cate.game.play.skill.passive.common.立即复活PH;

import java.util.List;

/**
 * 死亡后立即复活，拥有自身最大生命值60%的生命值，并附加【免伤强化】 单场战斗只能触发一次
 */
public class 烈火加身PH extends 立即复活PH {

	private double 恢复系数;

	private List<Integer> buffs;

	private int 冷却回合;

	//恢复系数=6000&buff=？？
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		恢复系数 = args.getWDouble("恢复系数", 0d);
		buffs = args.getIntList("buff");
		冷却回合 = args.getInt("冷却回合", 0);
	}

	@Override
	public void parseExt(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		冷却回合 = args.getInt("冷却回合", 冷却回合);
	}

	//上次复活回合
	private int lastRound;

	@Override
	protected boolean allowResurrect(ActionCtx action) {
		if (lastRound <= 0) {
			return true;
		}
		if (冷却回合 > 0) {
			return !FighterCD.inCD(lastRound, 冷却回合, action.getRound().index);
		} else {
			return false;
		}
	}

	@Override
	protected int getResurrectMax() {
		return -1;
	}

	@Override
	protected double healValue() {
		return skill.owner.attr.total().hpTotal() * 恢复系数;
	}

	@Override
	protected void onSuccess(ActionCtx action) {
		lastRound = action.getRound().index;
		if(XT.isNotBlank(buffs)){
			for (Integer buff : buffs) {
				skill.owner.buff.tryAddByTid(action, buff);
			}
		}
	}
}
